﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WCFDuplex.Services
{
    public class ChannelManager
    {
        private static ChannelManager _instance;
        public static ChannelManager GetInstance()
        {
            if (null == _instance)
            {
                lock (typeof(ChannelManager))
                {
                    _instance = new ChannelManager();
                }
            }
            return _instance;
        }
        private object _lockObject = new object();
        private List<IMessageServiceCallback> _channels = null; 
        private ChannelManager()
        {
            _channels = new List<IMessageServiceCallback>();
        }
        
        public List<IMessageServiceCallback> GetAllChannels()
        {
            return _channels;
        }

        public void AddChannel(IMessageServiceCallback channel)
        {
            lock (_lockObject)
            {
                _channels.Add(channel);
            }
        }

        public void RemoveChannel(IMessageServiceCallback chennel)
        {
            lock (_lockObject)
            {
                _channels.Remove(chennel);
            }
        }

        public void ClearChannels()
        {
            lock (_lockObject)
            {
                _channels.Clear();
            }
        }
    }
}
